<?php
!defined("IN_YCTOOL") && exit();
if($action == 'add' && $userid && $_FILES)
{
	//获取文件上传参数
	$tempfile = $_FILES['spPhotoFile0']['tmp_name'];
	$error    = $_FILES['spPhotoFile0']['error'];
	$size     = $_FILES['spPhotoFile0']['size'];
	$type     = $_FILES['spPhotoFile0']['type'];
	$realname = $_FILES['spPhotoFile0']['name'];

	$MAX_FILE = 2*1024*1024;//文件的最大值
	if($size > $MAX_FILE || !$size)
	{
		echo '<script language="javascript">alert("没有文件上传或者大小超过了限制[2M]");window.close();</script>';
		exit;
	}
	if($error != 0)
	{
		echo '<script language="javascript">alert("'.'error:'.$error.'");window.close();</script>';
		exit;
	}
	//photo 
	$FILE_TYPE_IMAGE0 = "image/jpeg";//图片文件的类型0
	$FILE_TYPE_IMAGE1 = "image/pjpeg";//图片文件的类型1
	$FILE_TYPE_IMAGE2 = "image/gif";//图片文件的类型2
	$FILE_TYPE_IMAGE3 = "image/x-png";//图片文件的类型3
	//$FILE_TYPE_IMAGE4 = "image/bmp";//图片文件的类型4

	if($type != $FILE_TYPE_IMAGE0 && $type != $FILE_TYPE_IMAGE1 && $type != $FILE_TYPE_IMAGE2 && $type != $FILE_TYPE_IMAGE3)
	{
		echo '<script language="javascript">alert("不支持此种格式上传。");window.close();</script>';
		exit;
	}

	$realname   = substr($realname, -4);
	$addtime    = time();
	$newName    = $userid . $addtime;

	require(DIR_COMM . 'key.func.php');
	$code = codeconfig($userid, $pre . $uidpathusr);

	$newfileImg = codeEn($newName, $code);

	$path	    = $data . $newfileImg . '.jpg';
	$ppath	    = $data . $newfileImg . '0.jpg';

	move_uploaded_file($tempfile, $pre . $path);

	func::imageResize($pre . $path, 240, 200, $pre . $ppath);
	func::imageResize($pre . $path, 50, 50, $pre . $data . $newfileImg . '00.jpg');

	$spImgThumb	= isset($_POST['spImgThumb']) ? $_POST['spImgThumb'] : "";
	if($spImgThumb)
	{
	    $userpic = $ppath;
	}
	else
	{
	    $userpic = $path;
	}
	$picclassid	= isset($_POST['picclassid']) ? $_POST['picclassid'] : 0;

	$user->addUpFile($userid, $newName, time(), $picclassid);

	unset($img);
}
?>
